﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using WebApi.Domain.Entity;
using WebApi.Entity;

namespace WebApi.Domain
{
    public class DbIntializerHelper
    {
        public static void Intialzer()
        {
            using (var db = new Admin1000DbContext())
            {
                var dbExist = db.Database.EnsureCreated();
                var tempBrand = db.Brands.Any();

                if (!tempBrand)
                {
                    var brand1 = new Brand
                    {
                        BrandName = "Iphone",
                        Description = "苹果"
                    };

                    var brand2 = new Brand
                    {
                        BrandName = "华为",
                        Description = "中国公司"
                    };
                    db.Brands.Add(brand1);
                    db.Brands.Add(brand2);
                    db.SaveChanges();
                    db.Product.AddRange(new Product[]
                    {
                    new Product
                    {
                        ProductName = "Iphone",
                        ShortDesc = "手机",
                        FullDesc = "iPhone 11 Pro Max搭载A13处理器，后置1200万像素三摄系统，支持原彩显示，支持18W快充以及无线充电，内置iOS 13操作系统。",
                        BrandId = brand1.Id
                    },

                    new Product
                    {
                        ProductName = "华为P40",
                        ShortDesc = "手机",
                        FullDesc = "华为P40搭载麒麟990 5G处理器，采用6.1英寸直屏，搭载5000万像素三摄系统，内置EMUI 10.1系统以及华为HMS服务。",
                        BrandId = brand2.Id
                    },

                    });

                    db.SaveChanges();
                }



            }
        }
    }
}
